/*
 * Created by JFormDesigner on Fri Apr 15 09:47:04 CST 2022
 */

package com.ZengQi.event.view;

import java.awt.event.*;

import com.ZengQi.event.controller.AddCommentViewController;
import com.ZengQi.event.controller.AnswerTopicViewController;
import com.ZengQi.event.entity.Topic;

import java.awt.*;
import javax.swing.*;
import javax.swing.GroupLayout;

/**
 * @author QI Zeng
 */
public class AnswerTopicView extends JFrame {
    private Topic topic;
    private String answer;
    private String finisher;
    public AnswerTopicView(Topic topic,String finisher) {
        this.finisher=finisher;
        this.topic=topic;
        initComponents();
        topicTxt.setText(topic.getTopicName());
        topicArea1.setText(topic.getTopicContent());
        answer=answerArea1.getText();
        setVisible(true);
        setLocationRelativeTo(null);
    }

    private void answerBtn(ActionEvent e) {
        answerBtnActionPerformed(e);
    }

    private void answerBtnActionPerformed(ActionEvent e) {
        if(answerArea1.getText()==null||"".equals(answerArea1.getText())){
            JOptionPane.showMessageDialog(this, "请不要交白卷！");

        }else {
            topic.setTopicAnswer(answerArea1.getText());
            AnswerTopicViewController answerTopicViewController=new AnswerTopicViewController();
            if(answerTopicViewController.isRight(topic,finisher)){
                JOptionPane.showMessageDialog(this, "回答正确！");
                    dispose();
            }else{
                JOptionPane.showMessageDialog(this, "回答错误！");

            }
        }
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        panel1 = new JPanel();
        label1 = new JLabel();
        topicTxt = new JTextField();
        contentLabel2 = new JLabel();
        scrollPane1 = new JScrollPane();
        topicArea1 = new JTextArea();
        label2 = new JLabel();
        scrollPane2 = new JScrollPane();
        answerArea1 = new JTextArea();
        button1 = new JButton();

        //======== this ========
        setTitle("\u505a\u9898\u5e2e");
        setIconImage(new ImageIcon(getClass().getResource("/bang.png")).getImage());
        Container contentPane = getContentPane();

        //======== panel1 ========
        {

            //---- label1 ----
            label1.setText("\u9898\u76ee\u540d\u79f0");

            //---- topicTxt ----
            topicTxt.setEditable(false);

            //---- contentLabel2 ----
            contentLabel2.setText("\u9898\u76ee\u5185\u5bb9");

            //======== scrollPane1 ========
            {

                //---- topicArea1 ----
                topicArea1.setEditable(false);
                scrollPane1.setViewportView(topicArea1);
            }

            //---- label2 ----
            label2.setText("\u8bf7\u5728\u6b64\u8f93\u5165\u7b54\u6848");

            //======== scrollPane2 ========
            {
                scrollPane2.setViewportView(answerArea1);
            }

            //---- button1 ----
            button1.setText("\u786e\u8ba4\u7b54\u9898");
            button1.addActionListener(e -> answerBtn(e));

            GroupLayout panel1Layout = new GroupLayout(panel1);
            panel1.setLayout(panel1Layout);
            panel1Layout.setHorizontalGroup(
                panel1Layout.createParallelGroup()
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addGroup(panel1Layout.createParallelGroup()
                            .addComponent(label1)
                            .addComponent(contentLabel2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                            .addComponent(topicTxt, GroupLayout.PREFERRED_SIZE, 197, GroupLayout.PREFERRED_SIZE)
                            .addComponent(scrollPane1, GroupLayout.PREFERRED_SIZE, 212, GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(label2)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(scrollPane2, GroupLayout.PREFERRED_SIZE, 351, GroupLayout.PREFERRED_SIZE)
                        .addGap(81, 81, 81)
                        .addComponent(button1)
                        .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
            panel1Layout.setVerticalGroup(
                panel1Layout.createParallelGroup()
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                            .addComponent(label1, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)
                            .addComponent(topicTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                        .addGroup(panel1Layout.createParallelGroup()
                            .addGroup(panel1Layout.createSequentialGroup()
                                .addGap(43, 43, 43)
                                .addComponent(contentLabel2))
                            .addGroup(panel1Layout.createSequentialGroup()
                                .addGap(30, 30, 30)
                                .addComponent(scrollPane1, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)))
                        .addGroup(panel1Layout.createParallelGroup()
                            .addGroup(panel1Layout.createSequentialGroup()
                                .addGap(43, 43, 43)
                                .addComponent(label2)
                                .addContainerGap())
                            .addGroup(GroupLayout.Alignment.TRAILING, panel1Layout.createSequentialGroup()
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(panel1Layout.createParallelGroup()
                                    .addGroup(GroupLayout.Alignment.TRAILING, panel1Layout.createSequentialGroup()
                                        .addComponent(scrollPane2, GroupLayout.PREFERRED_SIZE, 125, GroupLayout.PREFERRED_SIZE)
                                        .addGap(41, 41, 41))
                                    .addGroup(GroupLayout.Alignment.TRAILING, panel1Layout.createSequentialGroup()
                                        .addComponent(button1)
                                        .addGap(90, 90, 90))))))
            );
        }

        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(GroupLayout.Alignment.TRAILING, contentPaneLayout.createSequentialGroup()
                    .addComponent(panel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap())
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup()
                .addComponent(panel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JPanel panel1;
    private JLabel label1;
    private JTextField topicTxt;
    private JLabel contentLabel2;
    private JScrollPane scrollPane1;
    private JTextArea topicArea1;
    private JLabel label2;
    private JScrollPane scrollPane2;
    private JTextArea answerArea1;
    private JButton button1;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
